package com.zhairuihao.index;

import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;
import com.zhairuihao.classc.ClassService;
import com.zhairuihao.common.model.Image;
import com.zhairuihao.image.ImageService;

/**
 * 本 demo 仅表达最为粗浅的 jfinal 用法，更为有价值的实用的企业级用法 详见 JFinal 俱乐部: http://jfinal.com/club
 *
 * <p>IndexController
 */
public class IndexController extends Controller {
    @Inject
    ImageService imageService;
    @Inject
    ClassService classService;

    public void index() {

        Integer paraToInt0 = getParaToInt(0, 1);
        Integer paraToInt1 = getParaToInt(1, 1);
        Page<Image> paginate = imageService.paginate(paraToInt1, 1, 50);

        setAttr("class1", classService.list());
        setAttr("class2", classService.list(paraToInt0));
        setAttr("paginate", paginate);
        setAttr("paraToInt0", paraToInt0);
        setAttr("paraToInt1", paraToInt1);
        render("index.html");
    }



    public void detail() {
        Integer imageId = getParaToInt(0, 0);
        setAttr("data", imageService.findById(imageId));
        render("detail.html");
    }
}
